from base.base_other_page import BaseObject, BaseOperate, time
from utils import apperance_element_click


class CrystalAltarPage(BaseObject):
    """
    水晶祭坛页
    """
    def __init__(self):
        super().__init__()
        self.magic_crystal_ten_btn = "LotteryNormalCrystalRenderer", "开启十次"
        self.determine_btn = "BtnConfirm"
        # 退出祭坛按钮
        self.quit_altar_btn = "CloseButton"
        # self.continue_btn = "点击以继续"

    def find_magic_crystal_ten_btn(self):
        return self.get_element_path(self.magic_crystal_ten_btn)

    def find_determine_btn(self):
        return self.get_element_by_parent(self.determine_btn)

    def find_quit_altar_btn(self):
        return self.get_element_by_parent(self.quit_altar_btn)
    # 点击继续
    # def find_continue_btn(self):
    #     return self.get_element_by_text(self.continue_btn)


class CrystalAltarOperate(BaseOperate):
    def __init__(self):
        self.cap = CrystalAltarPage()

    # 点击魔法水晶的开启十次
    def click_magic_crystal_ten_btn(self):
        self.cap.find_magic_crystal_ten_btn().click()

    # 点击抽奖后的确定按钮
    def click_determine_btn(self):
        time.sleep(5)
        self.cap.find_determine_btn().click()
        print("-------点击抽奖结束页面确定------")

    # 点击祭坛退出
    def click_quit_altar_btn(self):
        self.cap.find_quit_altar_btn().click()

    # 如果存在就点击，不存在就略过
    def click_continue_btn(self):
        apperance_element_click(self.cap.find_determine_btn())


class CrystalAltarBusiness:
    def __init__(self):
        self.cao = CrystalAltarOperate()

    # 十次魔法水晶抽奖
    def luck_draw(self):
        # 点十次抽取
        self.cao.click_magic_crystal_ten_btn()
        # 如果出现抽到英雄就点继续
        self.cao.click_continue_btn()
        time.sleep(3)
        # 抽完就点确定
        self.cao.click_determine_btn()
        # 退出到沙盘
        self.cao.click_quit_altar_btn()

